package cn.stylefeng.guns.modular.fi.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.fi.entity.FiFreightDetailsLog;
import cn.stylefeng.guns.modular.fi.mapper.FiFreightDetailsLogMapper;
import cn.stylefeng.guns.modular.fi.model.params.FiFreightDetailsLogParam;
import cn.stylefeng.guns.modular.fi.model.result.FiFreightDetailsLogResult;
import  cn.stylefeng.guns.modular.fi.service.FiFreightDetailsLogService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 对账操作记录表 服务实现类
 * </p>
 *
 * @author zhangzh
 * @since 2024-11-06
 */
@Service
public class FiFreightDetailsLogServiceImpl extends ServiceImpl<FiFreightDetailsLogMapper, FiFreightDetailsLog> implements FiFreightDetailsLogService {

    @Override
    public void add(FiFreightDetailsLogParam param){
        FiFreightDetailsLog entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FiFreightDetailsLogParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FiFreightDetailsLogParam param){
        FiFreightDetailsLog oldEntity = getOldEntity(param);
        FiFreightDetailsLog newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FiFreightDetailsLogResult findBySpec(FiFreightDetailsLogParam param){
        return null;
    }

    @Override
    public List<FiFreightDetailsLogResult> findListBySpec(FiFreightDetailsLogParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FiFreightDetailsLogParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FiFreightDetailsLogParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FiFreightDetailsLog getOldEntity(FiFreightDetailsLogParam param) {
        return this.getById(getKey(param));
    }

    private FiFreightDetailsLog getEntity(FiFreightDetailsLogParam param) {
        FiFreightDetailsLog entity = new FiFreightDetailsLog();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
